function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function e(t, e, i) {
    return e in t ? Object.defineProperty(t, e, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = i, t;
}

function i(t, e) {
    if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var n = function() {
    function t(t, e) {
        for (var i = 0; i < e.length; i++) {
            var n = e[i];
            n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), 
            Object.defineProperty(t, n.key, n);
        }
    }
    return function(e, i, n) {
        return i && t(e.prototype, i), n && t(e, n), e;
    };
}(), o = t(require("../../utils/api2")), a = t(require("../../public/utils/authorize")), r = t(require("../../public/utils/qqmap")), d = t(require("./components/actionSheet/actionSheet")), s = t(require("./section-bargaining/section-bargaining")), c = t(require("./card-selector/card-selector")), u = t(require("./coupon-selector/coupon-selector")), $ = t(require("./section-groupon/section-groupon")), l = t(require("../link/link")), f = t(require("../image-manager/image-manager")), p = t(require("./section-quicklink/section-quicklink")), h = t(require("./video-manager/video-manager")), g = require("../../utils/plans"), y = t(require("../../utils/util")), v = function() {
    function t(n) {
        var r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        i(this, t), this.page = n, this.params = r, this.focused = !1;
        var v = this, m = wx.getSystemInfoSync();
        n.setData({
            $$editor: {
                toolbarShownIndex: "",
                types: t.getTypes(),
                apps: t.getApps(),
                marketings: t.getMarketings(),
                sections: [],
                actionSheetData: [],
                isIOS: -1 !== m.system.toLowerCase().indexOf("ios"),
                deleteLinkSource: []
            }
        }), n.$addListener("update.editorTypes", function(e) {
            function i(t, e, i) {
                t.forEach(function(n, o) {
                    e.some(function(t) {
                        return n.type === t;
                    }) || i.push(t[o]);
                });
            }
            var o = e.version, a = t.getTypes(), r = t.getApps(), d = t.getMarketings(), s = [], c = [], u = [];
            g.VERSION.SINGLE_PAGE === +o ? (i(r, [ "form", "quicklink", "search", "vr" ], s), 
            i(a, [ "marketing", "navigation" ], u)) : g.VERSION.COMPANY_DISPLAY === +o ? (i(r, [ "form", "search", "vr" ], s), 
            i(a, [ "marketing", "navigation" ], u)) : g.VERSION.CPMPANY_SITE !== +o && g.VERSION.SERVICE_ORDER !== +o || i(d, [ "bargaining", "groupon" ], c), 
            n.setData({
                "$$editor.apps": s.length ? s : r,
                "$$editor.types": u.length ? u : a,
                "$$editor.marketings": c.length ? c : d
            });
        }), d.default.addTo(n, "$$editor"), l.default.addTo(n, "$$editor", r), s.default.addTo(n, r), 
        c.default.addTo(n, r), u.default.addTo(n, r), $.default.addTo(n, r), p.default.addTo(n, r), 
        f.default.addTo(n, r), h.default.addTo(n, r), Object.assign(n, {
            $$onLinkSelect: function(t, e) {
                this.$$editorUpdateSectionData({
                    link: t[0]
                }, e, !0);
            },
            $$imageManagerOnChange: function(t, e, i, n) {
                t && t.length ? this.$$editorUpdateSectionData({
                    images: t,
                    model: e,
                    modid: i
                }, n, !0) : this.$$editorRemoveSection(n);
            },
            $$editorShowToolbar: function(t) {
                this.setData({
                    "$$editor.toolbarShownIndex": t.currentTarget.dataset.index
                });
            },
            $$editorHideToolbar: function(t) {
                this.setData({
                    "$$editor.toolbarShownIndex": ""
                });
            },
            $$editorCreateSection: function(t) {
                var e = t.currentTarget.dataset, i = e.type, n = e.index, o = "" + i.charAt(0).toUpperCase() + i.slice(1);
                if ("function" != typeof this["$$editorAdd" + o]) throw new Error("Editor section type not supported!");
                this["$$editorAdd" + o](n), this.$$editorHideToolbar();
            },
            $$editorAddSection: function(t, e) {
                Object.assign(t, {
                    id: Date.now()
                }), this.data.$$editor.sections.splice(e, 0, t), this.setData({
                    "$$editor.sections": this.data.$$editor.sections
                }), v.isFocusableType(t.type) && this.$$editorFocusIndex(e, t.type);
            },
            $$editorUpdateSection: function(t, i) {
                this.setData(e({}, "$$editor.sections[" + i + "]", t));
            },
            $$editorUpdateSectionData: function(t, e) {
                var i = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], n = this.data.$$editor.sections[e];
                n && (n.data = i ? Object.assign(n.data, t) : t, this.$$editorUpdateSection(n, e));
            },
            $$editorUpdateSectionType: function(t, e) {
                var i = this.data.$$editor.sections[e];
                i && (i.type = t, this.$$editorUpdateSection(i, e));
            },
            $$editorOnRemoveTap: function(t) {
                var e = t.currentTarget.dataset, i = e.index;
                if ("video" === e.type) {
                    var n = this.data.$$editor.sections[i].data.file.fieldid;
                    this.data.$$editor.deleteLinkSource.push(n);
                }
                this.$$editorRemoveSection(i);
            },
            $$editorRemoveSection: function(t) {
                this.data.$$editor.sections.splice(t, 1), this.setData({
                    "$$editor.sections": this.data.$$editor.sections
                });
            },
            $$editorDeleteLinkSource: function(t) {
                var e = this;
                t.length && o.default.site.attachment.delete({
                    data: {
                        aid: t.join(",")
                    }
                }).then(function() {
                    e.setData({
                        "$$editor.deleteLinkSource": []
                    });
                });
            },
            $$editorExchange: function(t) {
                var i, n = t.currentTarget.dataset.index, o = this.data.$$editor.sections;
                this.setData((i = {}, e(i, "$$editor.sections[" + (n - 1) + "]", o[n]), e(i, "$$editor.sections[" + n + "]", o[n - 1]), 
                i));
            },
            $$editorBlurIndex: function(t) {
                var i = this.data.$$editor.sections;
                this.data.$$editor.sections[t] && this.setData(e({}, "$$editor.sections[" + t + "].focus", !1)), 
                i.filter(function(t) {
                    return t.focus;
                }).length || v.blur();
            },
            $$editorFocusIndex: function(t, i) {
                var n = -1 !== m.system.toLowerCase().indexOf("ios");
                this.data.$$editor.sections[t] && this.setData(e({}, "$$editor.sections[" + t + "].focus", !0)), 
                !n || "title" !== i && "link" !== i ? v.focus() : v.blur();
            },
            $$editorSyncInput: function(t) {
                var i = t.currentTarget.dataset.index;
                this.data.$$editor.sections[i] && this.setData(e({}, "$$editor.sections[" + i + "].data.content", t.detail.value));
            },
            $$editorAddTitle: function(t) {
                this.$$editorAddSection({
                    type: "title",
                    data: {
                        content: "",
                        subtitle: "",
                        style: "",
                        selectedArr: [ 1, 2 ],
                        activeAlignId: 1
                    }
                }, t), this.$route("/pages/editor/title/form/form?content=&index=" + t);
            },
            $$editorEditTitle: function(t) {
                var e = t.currentTarget.dataset, i = e.content, n = e.index;
                this.$route("/pages/editor/title/form/form?content=" + i + "&index=" + n);
            },
            $$editorAddText: function(t) {
                this.$$editorAddSection({
                    type: "text",
                    data: {
                        content: ""
                    }
                }, t), this.$route("/pages/editor/text/content-editor/content-editor?type=text&content=&index=" + t);
            },
            $$editorEditText: function(t) {
                var e = t.currentTarget.dataset, i = e.content, n = e.index;
                this.$route("/pages/editor/text/content-editor/content-editor?type=text&content=" + i + "&index=" + n);
            },
            $$editorOnInputBlur: function(t) {
                this.$$editorBlurIndex(t.currentTarget.dataset.index);
            },
            $$editorOnInputFocus: function(t) {
                this.$$editorFocusIndex(t.currentTarget.dataset.index);
            },
            $$editorOnTextareaFocus: function(t) {
                var e = this, i = t.currentTarget.dataset.index, n = this.data.$$editor.sections[i];
                setTimeout(function() {
                    e.$$editorUpdateSectionData(Object.assign({}, n.data), i, !0);
                }, 200), this.$$editorOnInputFocus(t);
            },
            $$editorOnTextAreaAndInputBlur: function(t) {
                this.$$editorOnInputBlur(t), this.$$editorSyncInput(t);
            },
            $$editorAddImage: function(t) {
                this.data.$$editor.$$imageLayoutPicker ? this.setData({
                    "$$editor.$$imageLayoutPicker.key": t,
                    "$$editor.$$imageLayoutPicker.isShown": !0,
                    "$$editor.$$imageLayoutPicker.activeLayout": 0
                }) : this.setData({
                    "$$editor.$$imageLayoutPicker": {
                        key: t,
                        isShown: !0,
                        activeLayout: 0,
                        layoutList: [ {
                            id: 1,
                            model: "paved",
                            title: "平铺",
                            desc: "图片纵向平铺，图文混排"
                        }, {
                            id: 2,
                            model: "swiper",
                            title: "轮播",
                            desc: "多图轮播，自动播放"
                        }, {
                            id: 3,
                            model: "splicing",
                            title: "拼图",
                            desc: "拼图展示，快速链接至页面等"
                        } ]
                    }
                });
            },
            $$editorEditImage: function(t) {
                var e = t.currentTarget.dataset.index, i = this.data.$$editor.sections[e].data, n = i.images, o = i.model, a = void 0 === o ? "swiper" : o, r = i.modid, d = void 0 === r ? 1 : r;
                this.$$imageManagerEdit(n, a, d, e);
            },
            $$editorOnImageSwiperChange: function(t) {
                var e = t.currentTarget.dataset.index, i = t.detail.current;
                this.$$editorUpdateSectionData({
                    current: i
                }, e, !0);
            },
            $$editorAddLocation: function(t) {
                var e = this;
                wx.chooseLocation({
                    success: function(i) {
                        e.$$editorAddSection(v.createLocationData(i), t);
                    },
                    fail: function(t) {
                        return a.default.userLocation(t, function(t) {
                            return e.$$editorAddLocation(t);
                        });
                    }
                });
            },
            $$editorUpdateLocation: function(t) {
                var e = this, i = t.currentTarget.dataset.index;
                wx.chooseLocation({
                    success: function(t) {
                        e.$$editorUpdateSection(v.createLocationData(t), i);
                    },
                    fail: function(t) {
                        return a.default.userLocation(t, function(t) {
                            return e.editorUpdateLocation(t);
                        });
                    }
                });
            },
            $$editorOpenLocation: function(t) {
                var e = this, i = t.currentTarget.dataset.item.data;
                wx.openLocation(Object.assign({
                    scale: 15,
                    fail: function(t) {
                        return a.default.userLocation(t, function(t) {
                            return e.$$editorOpenLocation(t);
                        });
                    }
                }, i));
            },
            $$editorAddLink: function(t) {
                this.$$editorAddSection({
                    type: "link",
                    data: {
                        content: ""
                    }
                }, t);
            },
            $$editorOnLinkInput: function(t) {
                var i = t.currentTarget.dataset.index;
                if (this.data.$$editor.sections[i]) {
                    var n = t.detail.value;
                    this.setData(e({}, "$$editor.sections[" + i + "].data.content", n.slice(0, 20)));
                }
            },
            $$editorOnLinkBlur: function(t) {
                this.$$editorOnLinkInput(t), this.$$editorOnInputBlur(t);
            },
            $$editorAddCard: function(t) {
                var e = this;
                this.$$cardSelect([], function(i) {
                    e.$$editorAddSection({
                        type: "contact",
                        data: i[0]
                    }, t);
                });
            },
            $$editorUpdateCard: function(t) {
                var e = this, i = t.currentTarget.dataset.key, n = this.data.$$editor.sections[i].data;
                this.$$cardSelect([ n.cardid ], function(t) {
                    e.$$editorUpdateSectionData(t[0], i);
                });
            },
            $$editorAddVideo: function(t) {
                var e = r.sid || 0;
                this.$$uploadVideo(t, "add", e, "");
            },
            $$editorAddVr: function(t) {
                var e = r.sid || 0;
                this.$route("/pages/editor/vr/list/list?index=" + t + "&sid=" + e);
            },
            $$editorUpdateVR: function(t) {
                var e = t.currentTarget.dataset.key, i = this.data.$$editor.sections[e].data, n = i.aid, o = i.source, a = i.thumburl, d = i.spec, s = r.sid || 0;
                this.$route("/pages/editor/vr/form/form?aid=" + n + "&sid=" + s + "&source=" + o + "&thumburl=" + a + "&spec=" + d + "&index=" + e + "&mode=update");
            },
            $$editorAddNavigation: function(t) {
                this.$route("/pages/editor/navigation/nav-list/nav-list?key=" + t + "&mode=add");
            },
            $$editorUpdateNavigation: function(t) {
                var e = t.currentTarget.dataset.key, i = this.data.$$editor.sections[e].data, n = i.nav, o = i.category, a = n.nav, r = a.sid, d = a.navid, s = a.modid, c = a.template, u = 4 == +s ? o || "services_project" : c;
                this.$route("/pages/editor/navigation/content-list/content-list?key=" + e + "&sid=" + r + "&navid=" + d + "&modid=" + s + "&mode=edit&category=" + u);
            },
            $$editorUpdateNavLayout: function(t) {
                var e = this, i = t.currentTarget.dataset.key, n = this.data.$$editor.sections[i].data, o = n.nav, a = n.category, r = o.nav.modid, d = void 0;
                d = 5 == +r ? [ "田字格", "大图模式", "列表" ] : 4 == +r && "services_staff" === a ? [ "田字格", "轮播" ] : [ "列表", "田字格" ], 
                wx.showActionSheet({
                    itemList: d,
                    success: function(t) {
                        var o = t.tapIndex;
                        e.$$editorUpdateSectionData(Object.assign({}, n, {
                            layout: o + 1
                        }), i);
                    }
                });
            },
            $$editorAddApplication: function(t) {
                this.$$showActionSheet(t, "apps");
            },
            $$editorAddMarketing: function(t) {
                this.$$showActionSheet(t, "marketing");
            },
            $$editorAddQuicklink: function(t) {
                this.$$editorAddSection({
                    type: "quicklink",
                    data: []
                }, t), this.$route("/pages/editor/quicklink/quick-link/quick-link?sid=" + r.sid + "&index=" + t);
            },
            $$editorUpdateQuicklink: function(t) {
                var e = t.currentTarget.dataset.key;
                this.$$quicklinkEdit(e);
            },
            $$editorUpdateQCLayout: function(t) {
                var e = t.currentTarget.dataset.key;
                this.$$updateQCLayout(e);
            },
            $$editorAddForm: function(t) {
                var e = this;
                this.$route("/pages/editor/form/list/list?sid=" + r.sid), this.$removeListener("form:select"), 
                this.$addListener("form:select", function(i) {
                    var n = {
                        type: "form",
                        data: i
                    };
                    e.$$hasEqualForm(n) ? setTimeout(function() {
                        y.default.qAlert("同一个页面不能多次引用同一个表单");
                    }, 200) : e.$$editorAddSection(n, t);
                });
            },
            $$editorChangeForm: function(t) {
                var e = this, i = t.currentTarget.dataset.index;
                this.$route("/pages/editor/form/list/list?sid=" + r.sid), this.$removeListener("form:select"), 
                this.$addListener("form:select", function(t) {
                    var n = {
                        type: "form",
                        data: t
                    };
                    e.$$hasEqualForm(n) ? setTimeout(function() {
                        y.default.qAlert("同一个页面不能多次引用同一个表单");
                    }, 200) : e.$$editorUpdateSection(n, i);
                });
            },
            $$hasEqualForm: function(t) {
                return -1 !== this.data.$$editor.sections.filter(function(t) {
                    return "form" === t.type;
                }).findIndex(function(e) {
                    return e.data.form.formid === t.data.form.formid;
                });
            },
            $$editorAddSearch: function(t) {
                var e = this;
                this.$$editorAddSection({
                    type: "search",
                    data: []
                }, t), setTimeout(function() {
                    e.$$gotoSearchSettings(t);
                }, 30);
            },
            $$editorSearchSettings: function(t) {
                var e = t.currentTarget.dataset.index;
                this.$$gotoSearchSettings(e);
            },
            $$gotoSearchSettings: function(t) {
                this.$route("/pages/editor/search/settings/settings?index=" + t + "&sid=" + r.sid);
            },
            $$editorAddRaffle: function(t) {
                this.$$editorAddSection({
                    type: "raffle",
                    data: {}
                }, t);
            }
        });
    }
    return n(t, null, [ {
        key: "getTypes",
        value: function() {
            return [ {
                type: "title",
                desc: "标题"
            }, {
                type: "text",
                desc: "文本"
            }, {
                type: "image",
                desc: "图片"
            }, {
                type: "marketing",
                desc: "营销"
            }, {
                type: "application",
                desc: "应用"
            }, {
                type: "navigation",
                desc: "栏目"
            } ];
        }
    }, {
        key: "getApps",
        value: function() {
            return [ {
                type: "location",
                desc: "位置"
            }, {
                type: "card",
                desc: "名片"
            }, {
                type: "video",
                desc: "视频"
            }, {
                type: "form",
                desc: "表单"
            }, {
                type: "quicklink",
                desc: "导航"
            }, {
                type: "search",
                desc: "搜索"
            }, {
                type: "vr",
                desc: "VR全景"
            } ];
        }
    }, {
        key: "getMarketings",
        value: function() {
            return [ {
                type: "payment",
                desc: "买单"
            }, {
                type: "coupon",
                desc: "优惠券"
            }, {
                type: "groupon",
                desc: "拼团"
            }, {
                type: "bargaining",
                desc: "砍价"
            }, {
                type: "raffle",
                desc: "抽奖"
            } ];
        }
    }, {
        key: "getFocusableTypes",
        value: function() {
            return [ "link" ];
        }
    } ]), n(t, [ {
        key: "blur",
        value: function() {
            this.focused && (this.focused = !1, this.onBlur());
        }
    }, {
        key: "focus",
        value: function() {
            this.focused || (this.focused = !0, this.onFocus());
        }
    }, {
        key: "isFocusableType",
        value: function(t) {
            return -1 !== this.constructor.getFocusableTypes().indexOf(t);
        }
    }, {
        key: "createLocationData",
        value: function(t) {
            var e = {
                type: "location",
                data: {
                    address: t.address,
                    latitude: t.latitude,
                    longitude: t.longitude,
                    name: t.name
                }
            };
            return this.addLocationStaticMapUrl(e);
        }
    }, {
        key: "validSectionFilter",
        value: function(t) {
            return "title" === t.type || "text" === t.type ? "" !== t.data.content.trim() : "link" !== t.type || t.data.link;
        }
    }, {
        key: "fillLinkContent",
        value: function(t) {
            return t && "link" === t.type && !t.data.content.trim() && t.data.link && (t.data.content = t.data.link.title), 
            t;
        }
    }, {
        key: "addLocationStaticMapUrl",
        value: function(t) {
            var e = t.data, i = e.latitude, n = e.longitude, o = wx.getSystemInfoSync().screenWidth;
            return t && "location" === t.type && (t.url = r.default.createUrl({
                size: o + "*150",
                markers: "size:large|color:red|" + i + "," + n
            })), t;
        }
    }, {
        key: "removeLocationStaticMapUrl",
        value: function(t) {
            t && "location" === t.type && delete t.url;
        }
    }, {
        key: "formatData",
        value: function(t) {
            var e = this;
            return (t = t.filter(this.validSectionFilter)).forEach(function(t) {
                e.fillLinkContent(t), delete t.focus;
            }), t;
        }
    }, {
        key: "parseData",
        value: function(t) {
            return t.forEach(this.addLocationStaticMapUrl), t;
        }
    }, {
        key: "getData",
        value: function() {
            var t = this.page.data.$$editor.sections;
            return t && t.length ? (t = JSON.parse(JSON.stringify(t)), this.formatData(t)) : [];
        }
    }, {
        key: "setData",
        value: function(t) {
            t = JSON.parse(JSON.stringify(t)), this.page.setData({
                "$$editor.sections": this.parseData(t)
            });
        }
    } ]), t;
}();

exports.default = v;